package org.itsky.provider;

import org.itsky.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author sky
 * @Site cmtianxie163.com 2020/4/2 14:46
 */
@RestController
public class UserController {

    @GetMapping("/user/{ids}") //指定consumer传过来的多个id的格式是1，2，3，4，.....
    public List<User> getUserByIds(@PathVariable String ids){
        System.out.println(ids);
        String[] split = ids.split(",");
        List<User> users = new ArrayList<>();
        for (String s : split) {
            User u = new User();
            u.setId(Integer.parseInt(s));
            users.add(u);
        }
        return users;
    }

    @PostMapping("/user1")
    public User addUser1(User user){
        return user;
    }

    @PostMapping("/user2")
    public User addUser2(@RequestBody User user){
        return user;
    }

    @PutMapping("/user1")
    public void updateUser1(User user){
        System.out.println(user);
    }

    @PutMapping("/user2")
    public void updateUser2(@RequestBody User user){
        System.out.println(user);
    }
}
